home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / Orbit_SRC / stars.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-27  |  3.4 KB  |  156 lines

  1. /*
  2.     Amiga port by Oliver Gantert
  3.  
  4.     27.04.2000 - fixed some compiler warnings
  5. */
  6. /*
  7.  
  8. ORBIT, a freeware space combat simulator
  9. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  24.  
  25. */
  26.  
  27. #include "orbit.h"
  28. #include "stars.h"
  29.  
  30. /*
  31.  *  Stuff for the background starfield
  32.  */
  33.  
  34. void ReadStars()
  35. /*
  36.  *  Read in the stellar database
  37.  */
  38. {
  39.   int i;
  40.   double magmin, magmax;
  41.  
  42.   for (i=0; i<NSTARS; i++)
  43.   {
  44.     star[i].x = stars[i][0];
  45.     star[i].y = stars[i][1];
  46.     star[i].z = stars[i][2];
  47.     star[i].mag = stars[i][3];
  48.  
  49.     /* Reverse "magnitude" of magnitude (smaller mag means brighter star!) */
  50.     star[i].mag = 0.0 - star[i].mag;
  51.  
  52.     if (i == 0)
  53.     {
  54.       magmin = magmax = star[i].mag;
  55.     }
  56.     else
  57.     {
  58.       if (star[i].mag < magmin) magmin = star[i].mag;
  59.       if (star[i].mag > magmax) magmax = star[i].mag;
  60.     }
  61.   }
  62.  
  63.   /* Set the magnitudes */
  64.   for (i=0; i<NSTARS; i++)
  65.   {
  66.     star[i].bright = (star[i].mag - magmin) / (magmax - magmin);
  67.   }
  68.  
  69.   /* Find magnitude limits for sparse list */
  70.   for (i=0; i<NSTARS/10; i++)
  71.   {
  72.     if (i == 0)
  73.     {
  74.       magmin = magmax = star[i].mag;
  75.     }
  76.     else
  77.     {
  78.       if (star[i].mag < magmin) magmin = star[i].mag;
  79.       if (star[i].mag > magmax) magmax = star[i].mag;
  80.     }
  81.   }
  82.  
  83.   for (i=0; i<NSTARS/10; i++)
  84.   {
  85.     star[i].bright2 = (star[i].mag - magmin) / (magmax - magmin);
  86.   }
  87. }
  88.  
  89. void DrawStars()
  90. /*
  91.  *  "My god.  It's full of stars."
  92.  */
  93. {
  94.   /* Turn off 3D stuff */
  95.   glDisable (GL_DEPTH_TEST);
  96.   /* glDisable (GL_CULL_FACE); */
  97.   glDisable (GL_LIGHTING);
  98.   glDepthMask (GL_FALSE);
  99.   /* glDisable (GL_LIGHT0); */
  100.  
  101.   glPointSize (1);
  102.  
  103.   glCallList (star_list);
  104.  
  105.   /* Re-enable three-D stuff */
  106.   glEnable (GL_DEPTH_TEST);
  107.   /* glEnable (GL_CULL_FACE); */
  108.   glEnable (GL_LIGHTING);
  109.   glDepthMask (GL_TRUE);
  110.   /* glEnable (GL_LIGHT0); */
  111. }
  112.  
  113. void MakeStarList()
  114. /*
  115.  *  Construct display list for starfield
  116.  */
  117. {
  118.   int i, j;
  119.  
  120.   /* Make dense star field list */
  121.   star_list_dense = glGenLists (1);
  122.   glNewList (star_list_dense, GL_COMPILE);
  123.   glBegin (GL_POINTS);
  124.  
  125.   for (j=0; j<NSTARS; j++)
  126.   {
  127.     /* Plot stars backwards so bright ones plotted last */
  128.     i = (NSTARS - j) - 1;
  129.  
  130.     glColor3d (star[i].bright, star[i].bright, star[i].bright);
  131.     /*  glVertex4d (star[i].x, star[i].y, star[i].z, 0.00000); */
  132.     glVertex4d (star[i].x, star[i].y, star[i].z, 0.001);
  133.   }
  134.  
  135.   glEnd ();
  136.   glEndList();
  137.  
  138.   /* Make sparse list */
  139.   star_list_sparse = glGenLists (1);
  140.   glNewList (star_list_sparse, GL_COMPILE);
  141.   glBegin (GL_POINTS);
  142.  
  143.   for (j=0; j<(NSTARS/10); j++)
  144.   {
  145.     i = (NSTARS/10 - j) - 1;
  146.     glColor3d (star[i].bright2, star[i].bright2, star[i].bright2);
  147.     glVertex4d (star[i].x, star[i].y, star[i].z, 0.001);
  148.   }
  149.  
  150.   glEnd ();
  151.   glEndList();
  152.  
  153.   star_list = star_list_sparse;
  154.   if (starfield == 2) star_list = star_list_dense;
  155. }
  156.